home *** CD-ROM | disk | FTP | other *** search
/ Amiga Desktop Video CD / Amiga DeskTop Video CD.iso / install / forceicon / source / vollist.h < prev   
Text File  |  1994-06-23  |  8KB  |  322 lines

  1.  
  2. #define                                BSTRADDR(bstr)       ((char *)((((ULONG)bstr)<<2)+1))
  3.  
  4.  
  5. /**********************************************************************/
  6. /*                    Get device and volume lists                     */
  7. /**********************************************************************/
  8. static BOOL GetDevVolList(struct List *VolList)
  9. {
  10.     NewList(VolList);
  11.     VolList->lh_Type = 0;
  12.  
  13.     if(GetDosEntries(VolList, LDF_DEVICES))
  14.     {
  15.         if(GetDosEntries(VolList, LDF_VOLUMES))
  16.         {
  17.             SortList(VolList, FALSE);
  18.             return(TRUE);
  19.         }
  20.     }
  21.  
  22.     return(FALSE);
  23. }
  24.  
  25.  
  26.  
  27. /**********************************************************************/
  28. /*                     Collect available volumes                      */
  29. /**********************************************************************/
  30. static BOOL GetDosEntries(struct List *VolList, ULONG Mode)
  31. {
  32.     struct    DosList        *DList;
  33.     struct    VolEntry    *NewEntry;
  34.     BOOL            RetVal        = TRUE;
  35.  
  36.         // Lock DOS-List of Volumes
  37.  
  38.     if((DList = LockDosList(Mode|LDF_READ)))
  39.     {
  40.             // Loop for all entries
  41.  
  42.         while(RetVal && (DList = NextDosEntry(DList, Mode|LDF_READ)))
  43.         {
  44.                 // Alloc memory for new entry
  45.  
  46.             if((NewEntry = AllocVecPool(FIconSema, sizeof(struct VolEntry))))
  47.             {
  48.                     // Add to list
  49.  
  50.                 AddTail(VolList, (struct Node *)NewEntry);
  51.                 NewEntry->Link.ln_Name    = NewEntry->VolName;
  52.                 NewEntry->Link.ln_Type    = Mode;
  53.                 NewEntry->DriverTask    = DList->dol_Task;
  54.                 VolList->lh_Type++;
  55.  
  56.                 strcpy(NewEntry->VolName, ((char *)BADDR(DList->dol_Name) + 1));
  57.             }
  58.             else
  59.                 RetVal    = FALSE;
  60.         }
  61.  
  62.             // Unlock DOS-List again
  63.  
  64.         UnLockDosList(Mode|LDF_READ);
  65.     }
  66.  
  67.         // Now remove devices not being of block mounted type
  68.  
  69.     if(!IsListEmpty(VolList))
  70.     {
  71.         struct    Process        *MyProc    = (struct Process *)FindTask(NULL);
  72.         struct    VolEntry    *DelEntry;
  73.         char            DevName[134];
  74.         APTR            OldPtr;
  75.         BPTR            TestLock;
  76.         BOOL            RemoveEntry;
  77.  
  78.         Forbid();
  79.         OldPtr            = MyProc->pr_WindowPtr;
  80.         MyProc->pr_WindowPtr    = (void *)-1;
  81.         Permit();
  82.  
  83.         NewEntry        = (struct VolEntry *)VolList->lh_Head;
  84.  
  85.         do
  86.         {
  87.             DelEntry    = NewEntry;
  88.             NewEntry    = (struct VolEntry *)NewEntry->Link.ln_Succ;
  89.  
  90.             RemoveEntry    = FALSE;
  91.  
  92.             if(DelEntry->Link.ln_Type == LDF_DEVICES)
  93.             {
  94.                 RemoveEntry    = TRUE;
  95.  
  96.                 if(DelEntry->DriverTask)
  97.                 {
  98.                     strcpy(DevName, DelEntry->VolName);
  99.                     strcat(DevName, ":");
  100.  
  101.                     if((TestLock = Lock(DevName, ACCESS_READ)))
  102.                     {
  103.                         RemoveEntry    = FALSE;
  104.                         UnLock(TestLock);
  105.                     }
  106.                     else if(IoErr() != 209)
  107.                         RemoveEntry    = FALSE;
  108.                 }
  109.  
  110.             }
  111.  
  112.             if(RemoveEntry)
  113.             {
  114.                 Remove(DelEntry);
  115.                 FreeVecPool(FIconSema, DelEntry);
  116.                 VolList->lh_Type--;
  117.             }
  118.  
  119.         } while(NewEntry->Link.ln_Succ);
  120.  
  121.         Forbid();
  122.         MyProc->pr_WindowPtr    = OldPtr;
  123.         Permit();
  124.     }
  125.  
  126.  
  127.     if(!RetVal)
  128.         DisplayError(ERR_NOTALL, NULL);
  129.  
  130.     return(RetVal);
  131. }
  132.  
  133.  
  134.  
  135.  
  136. /**********************************************************************/
  137. /*                        Release Volume-Nodes                        */
  138. /**********************************************************************/
  139. static void FreeDevVolList(struct List *VolList)
  140. {
  141.     struct    Node    *DelNode;
  142.  
  143.     while((DelNode = RemHead(VolList)))
  144.         FreeVecPool(FIconSema, DelNode);
  145. }
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152. /**********************************************************************/
  153. /*             Sort the complete list of devices/volumes              */
  154. /**********************************************************************/
  155. static void SortList(struct List *VolList, BOOL DisplayType)
  156. {
  157.     UWORD    First, Last;
  158.  
  159.     if(DisplayType)
  160.     {
  161.         First    = LDF_VOLUMES;
  162.         Last    = LDF_DEVICES;
  163.     }
  164.     else
  165.     {
  166.         First    = LDF_DEVICES;
  167.         Last    = LDF_VOLUMES;
  168.     }
  169.  
  170.         // Sort partial lists within one list
  171.  
  172.     if(!IsListEmpty(VolList))
  173.     {
  174.         struct    VolEntry    *ThisEntry    = (struct VolEntry *)VolList->lh_Head;
  175.         UWORD    NumEntries            = VolList->lh_Type;
  176.         UWORD    Left = 0, Right = 0;
  177.  
  178.             // Find boundaries of first type of entries
  179.  
  180.         while(ThisEntry->Link.ln_Type == First && NumEntries)
  181.         {
  182.             Right++;
  183.             NumEntries--;
  184.             ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  185.         }
  186.  
  187.             // Sort`em
  188.  
  189.         if(Left < Right)
  190.         {
  191.             SortPartialList(VolList, Left, Right);
  192.             Left = Right;
  193.         }
  194.  
  195.             // Look for second type of entries
  196.  
  197.         while(ThisEntry->Link.ln_Type == Last && NumEntries)
  198.         {
  199.             Right++;
  200.             NumEntries--;
  201.             ThisEntry = (struct VolEntry *)ThisEntry->Link.ln_Succ;
  202.         }
  203.  
  204.             // Sort`em
  205.  
  206.         if(Left < Right)
  207.             SortPartialList(VolList, Left, Right);
  208.     }
  209. }
  210.  
  211.  
  212.  
  213. /**********************************************************************/
  214. /*            Sort partial list, either devices or volumes            */
  215. /**********************************************************************/
  216. static void SortPartialList(struct List *VolList, UWORD Left, UWORD Right)
  217. {
  218.     UWORD    i, j;
  219.  
  220.         // This is a simply Insertion Sort
  221.         // I don`t think that there will be too many entries,
  222.         // so this algorithm will do it. (IMHO)
  223.  
  224.     for(i = Left + 1; i < Right; i++)
  225.     {
  226.         struct    VolEntry    Spare, *CheckEntry;
  227.  
  228.             j = i;
  229.  
  230.             Spare        = *((struct VolEntry *)GetListEntry(VolList, i));
  231.             CheckEntry    = (struct VolEntry *)GetListEntry(VolList, j - 1);
  232.  
  233.             while(stricmp(CheckEntry->VolName, Spare.VolName) > 0 && j > Left)
  234.             {
  235.                 struct    VolEntry    *RightEntry = (struct VolEntry *)CheckEntry->Link.ln_Succ;
  236.  
  237.                 strcpy(RightEntry->VolName, CheckEntry->VolName);
  238.                 strcpy(RightEntry->IconName, CheckEntry->IconName);
  239.                 RightEntry->Left    = CheckEntry->Left;
  240.                 RightEntry->Top        = CheckEntry->Top;
  241.                 RightEntry->UseAlt    = CheckEntry->UseAlt;
  242.                 RightEntry->IconPos    = CheckEntry->IconPos;
  243.                 RightEntry->UseWin    = CheckEntry->UseWin;
  244.                 RightEntry->WinX    = CheckEntry->WinX;
  245.                 RightEntry->WinY    = CheckEntry->WinY;
  246.                 RightEntry->WinWidth    = CheckEntry->WinWidth;
  247.                 RightEntry->WinHeight    = CheckEntry->WinHeight;
  248.                 RightEntry->UseFlags    = CheckEntry->UseFlags;
  249.                 RightEntry->WinFlags    = CheckEntry->WinFlags;
  250.  
  251.  
  252.                 j--;
  253.                 CheckEntry = (struct VolEntry *)CheckEntry->Link.ln_Pred;
  254.             }
  255.  
  256.             CheckEntry = (struct VolEntry *)GetListEntry(VolList, j);
  257.             strcpy(CheckEntry->VolName, Spare.VolName);
  258.             strcpy(CheckEntry->IconName, Spare.IconName);
  259.             CheckEntry->Left    = Spare.Left;
  260.             CheckEntry->Top        = Spare.Top;
  261.             CheckEntry->UseAlt    = Spare.UseAlt;
  262.             CheckEntry->IconPos    = Spare.IconPos;
  263.             CheckEntry->UseWin    = Spare.UseWin;
  264.             CheckEntry->WinX    = Spare.WinX;
  265.             CheckEntry->WinY    = Spare.WinY;
  266.             CheckEntry->WinWidth    = Spare.WinWidth;
  267.             CheckEntry->WinHeight    = Spare.WinHeight;
  268.             CheckEntry->UseFlags    = Spare.UseFlags;
  269.             CheckEntry->WinFlags    = Spare.WinFlags;
  270.     }
  271. }
  272.  
  273.  
  274.  
  275. /**********************************************************************/
  276. /*                      Get an entry from a list                      */
  277. /**********************************************************************/
  278. static APTR GetListEntry(struct List *List, WORD EntryNum)
  279. {
  280.     struct    Node    *ThisEntry = NULL, *CheckEntry;
  281.  
  282.         // Search list for entry
  283.  
  284.     if(!IsListEmpty((struct List *)List) && EntryNum >= 0)
  285.     {
  286.         CheckEntry = List->lh_Head;
  287.  
  288.         while(CheckEntry->ln_Succ && EntryNum)
  289.         {
  290.             CheckEntry    = CheckEntry->ln_Succ;
  291.             EntryNum--;
  292.         }
  293.  
  294.         if(!EntryNum)
  295.             ThisEntry    = CheckEntry;
  296.     }
  297.  
  298.     return(ThisEntry);
  299. }
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306. /**********************************************************************/
  307. /*                Simple pattern match StrCmp function                */
  308. /**********************************************************************/
  309. static BOOL MyStrCmp(char *FromName, char *ToName)
  310. {
  311.     char    UpperFrom[132];
  312.     char    Pattern[270];
  313.  
  314.     strcpy(UpperFrom, FromName);
  315.     strupr(UpperFrom);
  316.  
  317.     if(ParsePatternNoCase(UpperFrom, Pattern, 270) != -1)
  318.         return((BOOL)(!MatchPatternNoCase(Pattern, ToName)));
  319.  
  320.     return((BOOL)(stricmp(FromName, ToName) != 0));
  321. }
  322.